﻿using System;
using System.Net;
using System.Data.Linq;

namespace Stimulus360.Services
{
    public static class ExceptionHelper
    {
        /// <summary>
        ///     Method to get the HTTP Status code mapped to the given exception
        /// </summary>
        /// <param name="exception">
        ///     The exception to be mapped
        /// </param>
        /// <returns>
        ///     The corresponding HTTP status code.
        /// </returns>
        public static HttpStatusCode GetStatusCode(Exception exception)
        {
            if (exception is FormatException)
                return HttpStatusCode.BadRequest;
            if (exception is ArgumentException)
                return HttpStatusCode.BadRequest;
            if (exception is ChangeConflictException)
                return HttpStatusCode.Conflict;
            return HttpStatusCode.InternalServerError;
        }
    }
}
